package bje;

import static org.junit.Assert.assertEquals;
import robocode.control.testing.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * JUnit testing of Surfer versus sample.Tracker. Verifies that Surfer always beats sample.Tracker.
 * 
 * @author Jeffrey Beck
 */
public class TestSurferVersusTracker extends RobotTestBed {

  /**
   * Specifies that sample.Tracker and Surfer are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Tracker, bje.Surfer";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * The actual test, which asserts that Surfer has won every round against sample.Tracker.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] battleResults = event.getIndexedResults();
    // Sanity check that results[1] is Surfer (not strictly necessary, but illustrative).
    BattleResults surferSesults = battleResults[1];
    String robotName = surferSesults.getTeamLeaderName();
    assertEquals("Check that results[1] is Surfer", robotName, "bje.Surfer*");

    // Check to make sure Surfer won every round.
    assertEquals("Check Surfer winner", surferSesults.getFirsts(), getNumRounds());
  }
}
